#!/bin/sh
# Build SD card image

BOARD_ID="${1}" # For example "bananapi"
CHIP_ID="${2}" # For example "allwinner-a10"
DEFCONFIG="${3}" # For example "Bananapi_defconfig"
TUPLE="${4}" # For example "arm-linux-gnueabihf"

set -ex

case "${CHIP_ID}" in
*a64|*h5)
    build-atf sun50i_a64 "${TUPLE}"
    export BL31="$(pwd)/arm-trusted-firmware/build/sun50i_a64/debug/bl31.bin"
    export SCP=/dev/null
    ;;
*h6)
    build-atf sun50i_h6 "${TUPLE}"
    export BL31="$(pwd)/arm-trusted-firmware/build/sun50i_h6/debug/bl31.bin"
    export SCP=/dev/null
    ;;
*h616|*h618)
    build-atf sun50i_h616 "${TUPLE}"
    export BL31="$(pwd)/arm-trusted-firmware/build/sun50i_h616/debug/bl31.bin"
    export SCP=/dev/null
    ;;
*)
    ;;
esac

build-u_boot "${DEFCONFIG}" "${TUPLE}"

# Copy U-Boot to 8192 bytes from start
dd if=u-boot/u-boot-sunxi-with-spl.bin of=tmp.img bs=1K seek=8 conv=notrunc
